<template>
    <div>微信登录中...</div>
</template>

<script lang='ts' setup>
import { onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { getWechatLoginUserInfo } from '@/api/login';
import { ElMessage } from 'element-plus';
import useLocalLogin from '../hooks/useLocalLogin';
sessionStorage.removeItem('currentRoute') //session 域清掉记录，登录后默认返回第一级菜单
const router = useRouter();

const code = router.currentRoute.value.query.code as string;

onMounted(async () => {
    try {
        const data = await getWechatLoginUserInfo(code);
        useLocalLogin(data);
    } catch (error) {
        ElMessage.error('登录失败');
        router.replace('/login');
    }
});



</script>
